﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Web.Mvc;

namespace GSLMS.Core
{
    public static class EnumHelper
    {
        public static SelectList ToSelectListText<TEnum>(object selectedValue = null)
        {
            var result = new SelectList(ToDictionary<TEnum>(), "Value", "Value", selectedValue);
            return result;
        }

        public static SelectList ToSelectList<TEnum>(object selectedValue = null)
        {
            var result = new SelectList(ToDictionary<TEnum>(), "Key", "Value", selectedValue);
            return result;
        }
               

        public static Dictionary<Int32, String> ToDictionary<TEnum>()
        {
            return Enum.GetValues(typeof(TEnum))
                .Cast<int>().OrderBy(c => c)
                .ToDictionary(e => e, e => Enum.GetName(typeof(TEnum), e));
        }
    }
}
